package com.zhongke.cotrun.controller;

import com.zhongke.cotrun.common.util.APIResponse;
import com.zhongke.cotrun.model.pojo.CompanyInfo;
import com.zhongke.cotrun.service.CompanyInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@RestController()
@Api(tags = "机构信息服务")
@RequestMapping("/companyInfo")
public class CompanyInfoController {
    @Autowired
    CompanyInfoService companyInfoService;

    @ResponseBody
    @GetMapping("/selectAll")
    @ApiOperation(value = "获取机构信息列表", notes = "获取机构信息列表", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    public APIResponse selectAll(){
        List<CompanyInfo> list = companyInfoService.selectAll();
        if(list!=null && list.size()>0){
            return APIResponse.returnSuccess(list);
        }
        return APIResponse.returnFail("暂无数据");
    }

    @PostMapping("/saveCompanyInfo")
    @ApiOperation(value = "保存机构信息", notes = "保存机构信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public APIResponse saveCompanyInfo(@ApiParam(value = "机构信息", required = true)@Validated CompanyInfo companyInfo){
        if(companyInfoService.saveCompanyInfo(companyInfo)){
            return APIResponse.returnSuccess("提交成功,请等待管理员审核");
        }
        return APIResponse.returnFail("保存失败");
    }

    @PostMapping("/updateCompanyInfo")
    @ApiOperation(value = "修改机构信息", notes = "修改机构信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    public APIResponse updateCompanyInfo(@RequestBody @Validated CompanyInfo companyInfo){
        if(companyInfoService.updateCompanyInfo(companyInfo)){
            return APIResponse.returnSuccess("提交成功,请等待管理员审核");
        }
        return APIResponse.returnFail("修改失败");
    }

}
